﻿using System;
using System.Collections.Generic;

namespace Hx.ADSyncPlatform.Infrastructure.Page
{

    /// <summary>
    /// 通用分页信息类
    /// </summary>
    public class PageResult<T>
    {

        public PageResult()
        {

        }

        public static PageResult<T> Default()
        {
            return new PageResult<T>(new List<T>(), 1, 0);
        }

        public PageResult(List<T> data, int pageIndex, int dataCount)
        {
            this.data = data;
            this.pagination = new Pagination();
            this.pagination.pageSize = this.data.Count;
            this.pagination.pageNum = pageIndex;
            this.pagination.dataCount = dataCount;
            int pageCount = (int)Math.Ceiling(dataCount * 1.0 / pagination.pageSize);
            this.pagination.pageCount = pageCount;
        }

        public PageResult(List<T> data, Pagination pagination)
        {
            this.data = data;
            this.pagination = pagination;
        }

        public Pagination pagination { get; set; } = new Pagination();
        /// <summary>
        /// 返回数据
        /// </summary>

        public List<T> data { get; set; }


    }


    public class Pagination : ICloneable
    {
        public int pageSize { get; set; } = 10;
        public int pageNum { get; set; } = 1;
        public int dataCount { get; set; }
        public int pageCount { get; set; }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
